package com.fulihui.wgj.consumer.listener;

import com.alibaba.fastjson.JSON;
import com.fulihui.wgj.facade.msg.BaseMsg;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 抽象监听器，规范子类行为
 *
 * @author: Levon
 * @date: 2018-06-29 10:25
 */
public abstract class AbstractListener<T extends BaseMsg> {

    /**
     * kafka监听方法抽象，规范实现
     *
     * @param record
     */
    abstract void listener(ConsumerRecord<String, String> record);

    /**
     * 执行具体业务
     *
     * @param msg 具体消息通配
     */
    void execute(T msg) {
        // do

    }

    /**
     * 统一消息拆包
     *
     * @param pack 消息包
     * @return
     */
   T unpack(String pack, Class<T> clazz) {
        return JSON.parseObject(pack, clazz);
    }
}
